from random import choice


class RandomizedSet:

    def __init__(self):
        self.nums = []
        self.indices = {}

    def insert(self, val: int) -> bool:
        if val in self.indices:
            return False
        self.indices[val] = len(self.nums)
        self.nums.append(val)
        return True


    def remove(self, val: int) -> bool:
        if val not in self.indices:
            return False
        index = self.indices[val]
        length = len(self.nums)
        last = self.nums[- 1]
        self.indices[last] = index
        self.nums[index] = last
        self.nums.pop()
        self.indices.pop(val)
        return True

    def getRandom(self) -> int:
        # random.choice()
        # 函数用于从非空序列中随机选择一个元素。
        return choice(self.nums)



# Your RandomizedSet object will be instantiated and called as such:
# obj = RandomizedSet()
# param_1 = obj.insert(val)
# param_2 = obj.remove(val)
# param_3 = obj.getRandom()